﻿using BUS;
using DTO;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QLBV_Nhom8
{
    public partial class frmYeuCauKhamDichVu : Form
    {
        public frmYeuCauKhamDichVu()
        {
            InitializeComponent();
        }

        private void frmYeuCauKhamDichVu_Load(object sender, EventArgs e)
        {
            txtTenBacSi.Text = Common.SessionNV.UserName;
            txtTenBenhNhan.Text = Common.PhieuKhamBenh.TenBenhNhan;
            txtKhac.Visible = false;
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked)
                txtKhac.Visible = true;
            else
                txtKhac.Visible = false;
        }

        private void btnXacNhan_Click(object sender, EventArgs e)
        {

            PhieuXetNghiemDTO xn = new PhieuXetNghiemDTO();
            xn.NgayXN = DateTime.Now;
            xn.NhanXetKetQuaXN = "";
            xn.MaPKB = Convert.ToInt32(Common.PhieuKhamBenh.MaPKB);
            int mapxn = PhieuXetNghiemBUS.ThemPhieuXetNghiem(xn);
            Common.MaPXN = mapxn;


            ChiTietPhieuXetNghiemDTO obj = new ChiTietPhieuXetNghiemDTO();
            ChiTietPhieuXetNghiemDTO obj1 = new ChiTietPhieuXetNghiemDTO();
            ChiTietPhieuXetNghiemDTO obj2 = new ChiTietPhieuXetNghiemDTO();

            if (checkBox1.Checked)
            {
                obj.TenXN = "Chụp X-Quang";
                obj.DonGia = 100000;
                obj.KetQuaXetNghiem = "";
                obj.MaPhieuXN = mapxn;
            }

            if (checkBox2.Checked)
            {
                obj1.TenXN = "Xét Nghiệm Máu";
                obj1.DonGia = 150000;
                obj1.KetQuaXetNghiem = "";
                obj1.MaPhieuXN = mapxn;
            }

            if (!string.IsNullOrEmpty(txtKhac.Text))
            {
                obj2.TenXN = txtKhac.Text;
                obj2.DonGia = 200000;
                obj2.KetQuaXetNghiem = "";
                obj2.MaPhieuXN = mapxn;
            }

            if (obj.DonGia > 0)
                ChiTietPhieuXetNghiemBUS.ThemChiTietPhieuXetNghiem(obj);
            if (obj1.DonGia > 0)
                ChiTietPhieuXetNghiemBUS.ThemChiTietPhieuXetNghiem(obj1);
            if (obj2.DonGia > 0)
                ChiTietPhieuXetNghiemBUS.ThemChiTietPhieuXetNghiem(obj2);
          

            this.Close();
        }
    }
}
